package exerciseService

import (
	"gin/dao/entity"
	"gin/dao/mapper/exercise"
	"gin/model/body"
	"gin/service/base"
	error2 "gin/util/error"
)

// Add 添加新的运动类型
func Add(p body.ExerciseAddParam) {
	count := exercise.MyListCount(p.Uid)
	if count >= 20 {
		error2.CustomPanic("用户最多只能自定义20个类型")
	}
	if p.ImgUrl == "" {
		p.ImgUrl = "/base/cover/exercise/de91953110f14f78953599ca7ef71b6a.png"
	}
	exercise.Add(p)
}

// Update 修改运动类型
func Update(p body.UpdateExerciseParam) {
	exercise.Update(p)
}

// Del 删除运动类型
func Del(id int64) {
	exercise.Del(id)
}

// List 获取运动类型列表
func List(uid int64) []*entity.Exercise {
	list := exercise.List(uid)
	for i, v := range list {
		list[i].ImgUrl = base.CompleteImgUrl(v.ImgUrl)
	}
	return list
}

// MyList 获取运动类型列表
func MyList(uid int64) []*entity.Exercise {
	list := exercise.MyList(uid)
	for i, v := range list {
		list[i].ImgUrl = base.CompleteImgUrl(v.ImgUrl)
	}
	return list
}

// Detail 获取运动类型详情
func Detail(id int64) entity.Exercise {
	info := exercise.Detail(id)
	info.ImgUrl = base.CompleteImgUrl(info.ImgUrl)
	return info
}
